package jsyf.oa.service.app;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import jsyf.oa.dao.app.UpdateDao;
import jsyf.oa.entity.app.UpdateEntity;
import jsyf.oa.facade.app.UpdateFacade;

@Service
@Transactional(rollbackFor = Exception.class)
@com.alibaba.dubbo.config.annotation.Service(protocol = {"dubbo"})
public class UpdateService implements UpdateFacade {
    @Autowired
    private UpdateDao updateDao;

    @Override
    public JSONObject getVersion() {
        StringBuffer condition = new StringBuffer();
        condition.append(" ORDER BY VERSION_CODE DESC ");
        List<JSONObject> list = updateDao.getJSONListByPage(condition.toString(), null, 1, 1);
        if (list != null && list.size() > 0) {
            return list.get(0);
        } else {
            return null;
        }
    }

    @Override
    public String save(String jsonData) {
        UpdateEntity entity = JSON.parseObject(jsonData, UpdateEntity.class);
        updateDao.add(entity);
        return entity.getId();
    }
}
